package com.fr.report.script.function;

import com.fr.report.script.Function;
import com.fr.report.script.Function.Type;
import com.fr.report.script.NormalFunction;
import com.fr.report.script.Primitive;
import com.fr.util.Utils;

public class RIGHT extends NormalFunction
{
  public Object run(Object[] paramArrayOfObject)
  {
    Object localObject2;
    if (paramArrayOfObject.length < 1)
      return Primitive.ERROR_NAME;
    Object localObject1 = paramArrayOfObject[0];
    int i = 1;
    if (paramArrayOfObject.length > 1)
    {
      localObject2 = paramArrayOfObject[1];
      if (localObject2 instanceof Number)
        i = ((Number)localObject2).intValue();
    }
    try
    {
      localObject2 = Utils.objectToString(localObject1);
      return ((String)localObject2).substring(((String)localObject2).length() - Math.max(0, Math.min(i, ((String)localObject2).length())));
    }
    catch (Exception localException)
    {
    }
    return "";
  }

  public Function.Type getType()
  {
    return Function.TEXT;
  }

  public String getCN()
  {
    return "RIGHT(text,num_chars): 根据指定的字符数从右开始返回文本串中的最后一个或几个字符。\nText:包含需要提取字符的文本串或单元格引用。\nNum_chars:指定RIGHT函数从文本串中提取的字符数。Num_chars不能小于0。如果num_chars大于文本串长度，RIGHT函数将返回整个文本。如果不指定num_chars，则默认值为1。\n示例:\nRIGHT(\"It is interesting\",6)等于“esting”。\nRIGHT(\"Share Holder\")等于“r”。\nRIGHT(\"Huge sale\",4)等于“sale”。";
  }

  public String getEN()
  {
    return "RIGHT(text,num_chars): RIGHT returns the last character or characters in a text string, based on the number of characters you specify.\nText is the text string containing the characters you want to extract.\nNum_chars specifies the number of characters you want RIGHT to extract.\n\nRemarks:\n1. Num_chars must be greater than or equal to zero. \n2. If num_chars is greater than the length of text, RIGHT returns all of text. \n3. If num_chars is omitted, it is assumed to be 1. \n\nExample:\n   RIGHT(\"It is interesting\",6) = \"esting\"\n   RIGHT(\"Share Holder\") = \"r\"\n   RIGHT(\"Huge sale\",4) = \"sale\"";
  }
}